/**
 * JAVACC DEMO 1.0
 * @copy right dwusoft company All rights reserved. 
 * @Package com.apache.audit.aop  
 */
package com.dwusoft.ius.able;

import java.util.Map;

import org.apache.log4j.Logger;

import com.apache.method.SystemRunnable;
import com.apache.rpc.util.LoadRpcService;

/**
 * description:  日志添加线程
 * @author Hou Dayu 创建时间：2014-8-8  
 * @Copyright(c)2014:北京--软件技术有限公司
 */
public class LogWriteRunnable extends SystemRunnable {

	private Logger log = Logger.getLogger(LogWriteRunnable.class);
	private Map<String, Object> logMap;

	public LogWriteRunnable(Map<String, Object> logMap) {
		this.logMap = logMap;
	}

	/**
	 * TODO 简单描述该方法的实现功能（可选）.  
	 * @see java.lang.Runnable#run()  
	 */
	public void run() {
		try {
			String mark = "false";
			String returnValue = String.valueOf(logMap.get("log_returnValue"));
			if ("save".equals(logMap.get("logType"))) {
				if (!isNull(returnValue)) {
					mark = "true";
				}
			} else if ("edit".equals(logMap.get("logType")) || "delete".equals(logMap.get("logType"))) {
				if (!isNull(returnValue)) {
					mark = returnValue;
				}
			} else {
				mark = returnValue;
			}
			if (!"true".equals(mark))
				return;
			LoadRpcService.service().doService("auditService", "logOperationSave", "xml", logMap, null);
		} catch (Throwable e) {
			log.error(e);
		}
	}

	/**
	 *判断对象数组是否为空
	 * 
	 * @param  object 对象数组
	 * @return        如果object为空返回true，不为空返回false 
	 */
	private boolean isNull(String str) {
		if (str == null) {
			return true;
		}
		str = str.trim();
		if ((str.equalsIgnoreCase("null")) || (str.equals(""))) {
			return true;
		}
		return false;
	}
}
